/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AdministracionPnl.java
 *
 * Created on 05-ene-2012, 20:56:43
 */
package vista.administracion;

import geografia.GestorVistaLocalidadesABM;
import javax.swing.JLayeredPane;
import vista.personas.pacientes.GestorVistaParentescosABM;
import vista.personas.profesionales.GestorEspecialidadesABM;
import util.GestorComponenteVista;
import util.components.ITablaABMPnl;

/**
 *
 * @author Raul
 */
public class AdministracionPnl extends javax.swing.JPanel implements ITablaABMPnl{

    private String nombrePanel="Administracion";
    private GestorVistaAdministracionPnl gestorVista;
       
    /** Creates new form AdministracionPnl */
    public AdministracionPnl() {
        initComponents();
    }

    public AdministracionPnl(GestorVistaAdministracionPnl gestorVista) {
        this();
        this.gestorVista = gestorVista;
        administracionABMPnl.setGestorVista(gestorVista);
        busquedaPnl.setGestorVista(gestorVista);
    }

    public GestorVistaAdministracionPnl getGestorVista() {
        return gestorVista;
    }

    public void setGestorVista(GestorVistaAdministracionPnl gestorVista) {
        this.gestorVista = gestorVista;
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        localidadesBtn = new javax.swing.JButton();
        parentescosBtn = new javax.swing.JButton();
        especialidadesBtn = new javax.swing.JButton();
        editorPnl = new javax.swing.JLayeredPane();
        jSeparator1 = new javax.swing.JSeparator();
        administracionABMPnl = new util.components.TablaABMPnl();
        busquedaPnl = new util.components.BusquedaPnl();

        localidadesBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/map_48.png"))); // NOI18N
        localidadesBtn.setText("Localidades");
        localidadesBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                localidadesBtnActionPerformed(evt);
            }
        });

        parentescosBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/geriatrics_48.png"))); // NOI18N
        parentescosBtn.setText("Parentescos");
        parentescosBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                parentescosBtnActionPerformed(evt);
            }
        });

        especialidadesBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/specialty_48.png"))); // NOI18N
        especialidadesBtn.setText("Especialidades");
        especialidadesBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                especialidadesBtnActionPerformed(evt);
            }
        });

        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);

        administracionABMPnl.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        administracionABMPnl.setImpresionHabilitada(false);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(especialidadesBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(parentescosBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(localidadesBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(editorPnl)
                    .addComponent(busquedaPnl, javax.swing.GroupLayout.DEFAULT_SIZE, 540, Short.MAX_VALUE)
                    .addComponent(administracionABMPnl, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(localidadesBtn)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(parentescosBtn)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(especialidadesBtn)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jSeparator1)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(busquedaPnl, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(administracionABMPnl, javax.swing.GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(editorPnl, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void localidadesBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_localidadesBtnActionPerformed
        setGestorVista(new GestorVistaLocalidadesABM());
        administracionABMPnl.setGestorVista(gestorVista);
        busquedaPnl.setGestorVista(gestorVista);
        reset();
    }//GEN-LAST:event_localidadesBtnActionPerformed

    private void especialidadesBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_especialidadesBtnActionPerformed
        setGestorVista(new GestorEspecialidadesABM());
        administracionABMPnl.setGestorVista(gestorVista);
        busquedaPnl.setGestorVista(gestorVista);
        reset();
    }//GEN-LAST:event_especialidadesBtnActionPerformed

    private void parentescosBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_parentescosBtnActionPerformed
        setGestorVista(new GestorVistaParentescosABM());
        administracionABMPnl.setGestorVista(gestorVista);
        busquedaPnl.setGestorVista(gestorVista);
        reset();
    }//GEN-LAST:event_parentescosBtnActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private util.components.TablaABMPnl administracionABMPnl;
    private util.components.BusquedaPnl busquedaPnl;
    private javax.swing.JLayeredPane editorPnl;
    private javax.swing.JButton especialidadesBtn;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JButton localidadesBtn;
    private javax.swing.JButton parentescosBtn;
    // End of variables declaration//GEN-END:variables

    public JLayeredPane getEditorPnl() {
        return editorPnl;
    }
    
    @Override
    public void agregarFilaTabla(Object[] fila) {
        GestorComponenteVista.agregarFilaTabla(administracionABMPnl.getTabla(), fila);
    }

    @Override
    public void actualizarTabla() {
        administracionABMPnl.actualizarTabla();
    }
    
    public void setearTituloPanelTabla(String title){
        administracionABMPnl.setBorder(
                javax.swing.BorderFactory.createTitledBorder(new util.components.RoundedBorder(), title));
    }
    
    @Override
    public void cargarTitulosTabla(Object[] titulos){
        GestorComponenteVista.cargarTitulosTabla(administracionABMPnl.getTabla(), titulos);
    }

    public void cargarTitulosTabla(Object[] titulos, int[] anchos) {
        GestorComponenteVista.cargarTitulosTabla(administracionABMPnl.getTabla(), titulos,anchos);
    }
    
    public void agregarFiltrosDeBusqueda(String [] filtros){
        busquedaPnl.agregarFiltrosDeBusqueda(filtros);
    }

    private void reset(){
        gestorVista.setFormulario(this);
        editorPnl.removeAll();
        editorPnl.repaint();
        gestorVista.inicializarVista();
    }
    
    //Sobreescritura del metodo equals para evitar que se abran dos pestanias iguales
    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final AdministracionPnl other = (AdministracionPnl) obj;
        if ((this.nombrePanel == null) ? (other.nombrePanel != null) : !this.nombrePanel.equals(other.nombrePanel)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 23 * hash + (this.nombrePanel != null ? this.nombrePanel.hashCode() : 0);
        return hash;
    }


}
